package other;

import java.util.Scanner;

public class D230901 {
    // 二进制、八进制、十六进制 转 十进制
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String table1 = "0123456789ABCDEF";
        String[] arr1 = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001",
                "1010", "1011", "1100", "1101", "1110", "1111"};
        String table2 = "012345678";
        String[] arr2 = {"000", "001", "010", "011", "100", "101", "110", "111"};

        while (in.hasNext()) {
            String str = in.next();
            int res = 0;
            // 记录是否错误
            boolean flag = false;

            if (str.length() > 2 && (str.substring(0, 2).equals("0b") || str.substring(0, 2).equals("0B"))) {
                // 二进制转十进制
                res = func(str.substring(2));
            } else if (str.length() > 2 && (str.substring(0, 2).equals("0x") || str.substring(0, 2).equals("0X"))) {
                // 十六进制
                // 转为二进制
                StringBuilder sb = new StringBuilder();
                for (int i = 2; i < str.length(); i++) {
                    char ch = str.charAt(i);
                    int index = table1.indexOf(ch);
                    if (index == -1) {
                        flag = true;
                        break;
                    }
                    sb.append(arr1[index]);
                }

                if (!flag) {
                    // 二进制转十进制
                    res = func(sb.toString());
                }
            } else if (str.length() > 1 && str.charAt(0) == '0') {
                // 八进制
                // 转为二进制
                StringBuilder sb = new StringBuilder();
                for (int i = 1; i < str.length(); i++) {
                    char ch = str.charAt(i);
                    int index = table2.indexOf(ch);
                    if (index == -1) {
                        flag = true;
                        break;
                    }
                    sb.append(arr2[index]);
                }

                if (!flag) {
                    // 二进制转十进制
                    res = func(sb.toString());
                }
            } else {
                try {
                    res = Integer.parseInt(str);
                } catch (Exception e) {
                    flag = true;
                }
            }

            if (flag || res == -1) {
                System.out.println("error");
            } else {
                System.out.println(res);
            }
        }
    }
    private static int func(String str) {
        // 二进制转十进制
        int n = 0;
        int res = 0;
        for (int i = str.length() - 1; i >= 0; i--, n++) {
            char ch = str.charAt(i);
            if (ch != '0' && ch != '1') {
                return -1;
            }
            res += (ch - '0') * Math.pow(2, n);
        }
        return res;
    }
}
